﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using WooCoo.Data;

namespace WooCoo.ObjectModel
{
    /// <summary>
    /// Repository模式接口
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <remarks>由于事务具有较强的上下文关系，在实体Repsitory接口中不涉及事务提交，需要配合事务上下文进行</remarks>
    public interface  IRepository<T> where 
        T:Entity
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        IQueryable<T> AsQueryable();
        /// <summary>
        /// 根据主键值，查询实体，需要注意本框架目前只支持采用单主键式。
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        T Find(params object[] keys);
        /// <summary>
        /// 添加实体对象到数据上下文
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity"></param>
        /// <returns></returns>
        int Add(T entity);        

        /// <summary>
        /// 从数据上下文中删除实体
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="searchCondition"></param>
        /// <returns></returns>
        int Remove(T entity);

        /// <summary>
        /// 根据[lambda条件表达式]从数据上下文中删除实体
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="predicate"></param>
        /// <returns></returns>
        int RemoveRange(Expression<Func<T, bool>> predicate);

        /// <summary>
        /// 实体更新至数据上下文
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity"></param>
        /// <returns></returns>
        int Update(T entity);
    }
}
